#include "DelegateTest.h"
#include "CBL_Defines.h"
#include "CBL_Delegate.h"

class TestClass
{
public:
    
    TestClass() : m_Value(0) {}
    
    void Function1() 					{ m_Value = 1; }
    void Function2(void* _pData) 		{ m_Value = *(uint32*)_pData; }
    
    void Function3() const				{ m_Value2 = 1; }
    void Function4(void* _pData) const	{ m_Value2 = *(uint32*)_pData; }
    
public:
    
    uint32 m_Value;
    mutable uint32 m_Value2;
};

BEGIN_TEST_CASE_IMPLEMENTATION(CDelegateTest)

	TestClass Test1;
	const TestClass Test2;

	Cb::CDelegate Delegate1      = Cb::CDelegate::Create<TestClass, &TestClass::Function1>(&Test1);
	Cb::CInOutDelegate Delegate2 = Cb::CInOutDelegate::Create<TestClass, &TestClass::Function2>(&Test1);
	
	Cb::CConstDelegate Delegate3      = Cb::CConstDelegate::Create<TestClass, &TestClass::Function3>(&Test2);
	Cb::CInOutConstDelegate Delegate4 = Cb::CInOutConstDelegate::Create<TestClass, &TestClass::Function4>(&Test2);
	
	uint32 Value1 = 5;

	Delegate1();
	CHECK(Test1.m_Value == 1,		"> Delegate with no parameter test failed.")

	Delegate2(&Value1);
	CHECK(Test1.m_Value == Value1,	"> Delegate with parameter test failed.")
	
	Delegate3();
    CHECK(Test2.m_Value2 == 1,		"> Const Delegate with no parameter test failed.")

    Delegate4(&Value1);
    CHECK(Test2.m_Value2 == Value1,	"> Const Delegate with parameter test failed.")

END_TEST_CASE_IMPLEMENTATION